package ShenBlueCenter.Inc;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import ShenBlueInc.Center.Card_Center;
import ShenBlueTool.isString;

/**
 * Servlet implementation class CreditCardTips
 */
@WebServlet("/imp/CreditCardTips")
public class CreditCardTips extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CreditCardTips() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int mode=Integer.parseInt(request.getParameter("mode"));//1标记还款
		Card_Center cardC=new Card_Center();
		response.setContentType("application/json");
		response.setCharacterEncoding("utf8");
		HttpSession session=request.getSession();
		String user_id=(String) session.getAttribute("User_id");
		isString isString =new isString();
		if(mode==1) {
			String card_id=request.getParameter("card_id");
			if(isString.IsEmpty(card_id)) {
				response.getWriter().write("{\"error\":\"禁止留空\"}");
				return;
			}
			if(!cardC.SelectCardID(user_id, card_id)) {
				response.getWriter().write("{\"error\":\"您并无该卡号\"}");
				return;
			}
			if(cardC.TipsCardRepay(user_id,card_id)) {
				response.getWriter().write("{\"error\":\"还款失败\"}");
				return;
			}
			response.getWriter().write("{\"msg\":\"还款成功\"}");
			return;
		}
	}

}
